package com.lucher.mes.controller;



import com.lucher.mes.common.XxqHttpUtils;
import com.lucher.mes.dao.ProducescheduleproblemMapper;
import com.lucher.mes.service.ISystemparaService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 用户控制层
 */
@Controller
@Scope("prototype")
@RequestMapping(value = "/xxq")
public class PlugsController extends BaseController {


    @Autowired
    private ProducescheduleproblemMapper mp001;

    @Autowired
    private ISystemparaService systemparaService;



    @ResponseBody
    @RequestMapping(value = "/index", produces = "application/json;charset=GBK")
    public String index() {
       return sendProblemNotice("001");
    }






    public String sendProblemNotice(String linecode) {
        if(linecode.equals(null) ){
            return  null;
        }

        try {


            String urlKey="send_qc_bad_url";
            //发送质检不合格数据
            String sendQcBadUrl = systemparaService.findSystemParaByCodeStr(urlKey);
            if(sendQcBadUrl.equals(null) ){
                return  null ;
            }

            //获取有问题的人员列表
            List<Map<String, Object>> personList = mp001.getProblemPersonList(linecode);

            if (personList.isEmpty()) {
                return null;
            }

            for (Map<String, Object> item : personList) {

                List<Map<String, Object>> problemList = mp001.getProblemListByLinecode(linecode,(String) item.get("prisonercode"));
                item.put("problem",problemList);
                item.put("total",problemList.size() );

                JSONObject mainJson = new JSONObject();
                mainJson.put("method","qcbad");
                mainJson.put("client",item);
                String jsonStr =  mainJson.toString();
                XxqHttpUtils.sendJsonByPost(sendQcBadUrl,jsonStr );
            }

        } catch (Exception e) {
            e.printStackTrace();
        }


        return "OK";

    }


}
